package com.ruoyi.ade.controller;

import com.ruoyi.ade.domain.AdeLlmLab;
import com.ruoyi.ade.service.IAdeLlmExecuteService;
import com.ruoyi.ade.service.IAdeLlmLabService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Ade LLM LabsController
 * 
 * @author wxh
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/ade/llmlab")
public class AdeLlmLabController extends BaseController
{
    @Autowired
    private IAdeLlmLabService adeLlmLabService;

    @Autowired
    private IAdeLlmExecuteService adeLlmExecuteService;

    @PutMapping("/execute/{id}")
    public AjaxResult execute(@PathVariable("id") Long id){
        try {
            adeLlmExecuteService.execute(id);
            return AjaxResult.success();
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 查询Ade LLM Labs列表
     */
    @PreAuthorize("@ss.hasPermi('ade:llmlab:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdeLlmLab adeLlmLab)
    {
        startPage();
        List<AdeLlmLab> list = adeLlmLabService.selectAdeLlmLabList(adeLlmLab);
        return getDataTable(list);
    }

    /**
     * 导出Ade LLM Labs列表
     */
    @PreAuthorize("@ss.hasPermi('ade:llmlab:export')")
    @Log(title = "Ade LLM Labs", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdeLlmLab adeLlmLab)
    {
        List<AdeLlmLab> list = adeLlmLabService.selectAdeLlmLabList(adeLlmLab);
        ExcelUtil<AdeLlmLab> util = new ExcelUtil<AdeLlmLab>(AdeLlmLab.class);
        util.exportExcel(response, list, "Ade LLM Labs数据");
    }

    /**
     * 获取Ade LLM Labs详细信息
     */
    @PreAuthorize("@ss.hasPermi('ade:llmlab:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(adeLlmLabService.selectAdeLlmLabById(id));
    }

    /**
     * 新增Ade LLM Labs
     */
    @PreAuthorize("@ss.hasPermi('ade:llmlab:add')")
    @Log(title = "Ade LLM Labs", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdeLlmLab adeLlmLab)
    {
        return toAjax(adeLlmLabService.insertAdeLlmLab(adeLlmLab));
    }

    /**
     * 修改Ade LLM Labs
     */
    @PreAuthorize("@ss.hasPermi('ade:llmlab:edit')")
    @Log(title = "Ade LLM Labs", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdeLlmLab adeLlmLab)
    {
        return toAjax(adeLlmLabService.updateAdeLlmLab(adeLlmLab));
    }

    /**
     * 删除Ade LLM Labs
     */
    @PreAuthorize("@ss.hasPermi('ade:llmlab:remove')")
    @Log(title = "Ade LLM Labs", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adeLlmLabService.deleteAdeLlmLabByIds(ids));
    }
}
